package connect;

import java.io.*;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by 32706 on 2017/3/12.
 * 该类定义数据传送类
 */
public class ConnectionData implements Serializable {
    private boolean function = false;//功能字段
    //    String phone = null;//用户手机号
//    String password = null;//用户密码
    String token = "";//token数据
    String state = "successful";
    String wrong_info = null;
    Picture picture = null;//传输的图片集合
    private boolean isimage = false;

    public ConnectionData(){

    }
    public ConnectionData(String str){
        this.token=str;
    }

    public ConnectionData(File image) throws IOException {
        InputStream in = new FileInputStream(image);
        byte[] photo = new byte[in.available()];
        in.read(photo);
        in.close();
        this.picture = new Picture();
        this.picture.setPic_data(photo);
        this.picture.setPic_name(image.getName());
        this.isimage=true;
    }

    public ConnectionData(Picture pic){
        this.picture=pic;
        this.isimage=true;
    }

    /**
     * 设置各个参数
     **/
    public void setFunction() {
        this.function = true;
    }

    //    public void setPhone(String phone) {
//        this.phone = phone;
//    }
//
//    public void setPassword(String password) {
//        this.password = password;
//    }
//
    public void setToken(String tk) { this.token = tk; }

//    public void setPicture_list(List<Picture> in) {
//        if (this.picture_list == null)
//            picture_list = new ArrayList<>();
//        this.picture_list.addAll(in);
//    }

    public void setState(String in) {
        this.state = in;
    }

    public void setWrong_info(String info) {
        if (this.wrong_info == null) {
            this.wrong_info = info;
        } else {
            this.wrong_info += info;
        }
    }

    public void setIsImage() { isimage = true; }


    /**
     * 取出各个参数
     **/
    public boolean getFunction() {
        return this.function;
    }

//    public String getPhone() {
//        return this.phone;
//    }
//
//    public String getPassword() {
//        return this.password;
//    }

    public String getToken() { return this.token; }

//    public List<Picture> getPicture_list() {
//        return this.picture_list;
//    }
    public Picture getPicture(){ return this.picture; }

    public String getState() {
        return this.state;
    }

    public String getWrong_info() {
        return this.wrong_info;
    }

    public boolean isImage() { return isimage; }
}

